/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author nMoncho
 */
public class SimpleSessionFactory {

    private static SessionFactory sessionFactory = null;
    
    public static SessionFactory getSessionFactory(Properties prop) {
        if(sessionFactory == null){
            try {
                sessionFactory = buildConfiguration(prop).buildSessionFactory();
            } catch (Throwable ex) {
                System.err.println("Initial SessionFactory creation failed." + ex);
            }
        }
        
        return sessionFactory;
    }

    public static Configuration buildConfiguration(Properties dbProperties){
        Configuration cfg = new Configuration();
//        cfg.setProperties(dbProperties);

        cfg.addResource("hbm/Barrio.hbm.xml");
        cfg.addResource("hbm/Bebida.hbm.xml");
        cfg.addResource("hbm/Boliche.hbm.xml");
        cfg.addResource("hbm/DiaSalida.hbm.xml");
        cfg.addResource("hbm/MedioComunicacion.hbm.xml");
        cfg.addResource("hbm/Musica.hbm.xml");
        cfg.addResource("hbm/Persona.hbm.xml");
        cfg.addResource("hbm/Profesion.hbm.xml");
        cfg.addResource("hbm/PuntosAmigos.hbm.xml");
        cfg.addResource("hbm/Visita.hbm.xml");

        //Default Config
        cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.OracleDialect");
        cfg.setProperty("hibernate.connection.driver_class", "oracle.jdbc.OracleDriver");
        cfg.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@//localhost:1521/XE");
        cfg.setProperty("hibernate.connection.username", "nuvvia");
        cfg.setProperty("hibernate.connection.password", "kubik");
        cfg.setProperty("hibernate.show_sql", "true");

        return cfg;
    }

}
